1293B - JOE is on TV - CodeForces Solution


combinatorics greedy math *1000

Please click on ads to support us..

Python Code:

import sys, math
import heapq

from collections import deque

input = sys.stdin.readline

hqp = heapq.heappop
hqs = heapq.heappush


def ip(): return int(input())
def sp(): return str(input().rstrip())

def mip(): return map(int, input().split())
def msp(): return map(str, input().split().rstrip())

def lmip(): return list(map(int, input().split()))
def lmsp(): return list(map(str, input().split().rstrip()))


def gcd(x, y):
    while y:
        x, y = y, x % y
    return x


def lcm(x, y):
    return x * y // gcd(x, y)


def isPrime(x):
    if x <= 1: return False
    for i in range(2, int(x ** 0.5) + 1):
        if x % i == 0:
            return False
    return True



def find(x):
    if x == p[x]:
        return x
    q = find(p[x])
    p[x] = q
    return q


def union(x, y):
    x = find(x)
    y = find(y)

    if x != y:
        p[y] = x


def getPow(a, x):
    ret = 1
    while x:
        if x & 1:
            ret = (ret * a) % MOD
        a = (a * a) % MOD
        x >>= 1
    return ret



n = ip()
ans = 0
for i in range(1, n + 1):
    ans += 1/i
print(ans)

C++ Code:

#include<bits/stdc++.h>
#define Salah7 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define el '\n'
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define co continue;
#define br break;
/*
Many mistakes breed mastery
*/
using namespace std;

void they_call_me_007()
{
    //freopen("cowsignal.in", "r", stdin);
	//freopen("cowsignal.out", "w", stdout);
}
void solve()
{
    double n;
    cin >> n;
    double ans = 0;
    while (n)
    {
        ans+= 1/n;
        n--;
    }
    cout<<fixed<<setprecision(12)<<ans;
}
int main()
{
    Salah7
    they_call_me_007();
    int T = 1;
    //cin>>T;
    while (T--)
    {
        solve();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1463B - Find The Array
1538C - Number of Pairs
621B - Wet Shark and Bishops
476B - Dreamoon and WiFi
152C - Pocket Book
1681D - Required Length
1725D - Deducing Sortability
1501A - Alexey and Train
721B - Passwords
1263D - Secret Passwords
1371B - Magical Calendar
1726E - Almost Perfect
1360C - Similar Pairs
900A - Find Extra One
1093D - Beautiful Graph
748A - Santa Claus and a Place in a Class
1511B - GCD Length
676B - Pyramid of Glasses
597A - Divisibility
1632A - ABC
1619D - New Year's Problem
242B - Big Segment
938A - Word Correction
159C - String Manipulation 10
258A - Little Elephant and Bits
1536C - Diluc and Kaeya
1428C - ABBB
1557A - Ezzat and Two Subsequences
255A - Greg's Workout
1059A - Cashier